﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Drawing;
using System.Text.RegularExpressions;

namespace mjRegister.BAL
{
    public class SohuVerifyCode
    {
        public string rcode = string.Empty;
        public CookieCollection cc = new CookieCollection();
        //获取验证码
        public Image GetVerifyCodeImage()
        {
            Random r = new Random();
            rcode = r.NextDouble().ToString();
            HttpProc hp = new HttpProc(string.Format("http://passport.sohu.com/servlet/Captcha?time={0}", rcode));
            Image img = null;
            HttpWebRequest 请求 = hp.CreateRequest();
            HttpWebResponse 响应 = null;
            try
            {
                响应 = (HttpWebResponse)请求.GetResponse();
                img = Image.FromStream(响应.GetResponseStream());
                if (响应.Cookies.Count > 0)
                {
                    cc = 响应.Cookies;
                }
                if (img != null)
                {
                    return img;
                }
                else
                    throw new Exception("不能获取验证码。");
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

    }
}
